global infile "DataMain.dta"
global outfile "$results/Table 7"


* Table 7. Estimates by apartment characteristics

use "$infile", clear
keep if rooms <= 2 & rooms != .
reghdfe logwater treat, absorb(datasethome datasetweek) cluster(home)
leveleffects
outreg2 using "$outfile", keep(treat) nocon 2aster dec(3) word ap ///
addstat(pre, $prem, effect, $effectm, transbeta, $transbeta) 

use "$infile", clear
keep if rooms > 2 & rooms != .
reghdfe logwater treat, absorb(datasethome datasetweek) cluster(home)
leveleffects
outreg2 using "$outfile", keep(treat) nocon 2aster dec(3) word ap ///
addstat(pre, $prem, effect, $effectm, transbeta, $transbeta) 

use "$infile", clear
keep if m2 <= 65 & m2 != .
reghdfe logwater treat, absorb(datasethome datasetweek) cluster(home)
leveleffects
outreg2 using "$outfile", keep(treat) nocon 2aster dec(3) word ap ///
addstat(pre, $prem, effect, $effectm, transbeta, $transbeta) 

use "$infile", clear
keep if m2 > 65 & m2 != .
reghdfe logwater treat, absorb(datasethome datasetweek) cluster(home)
leveleffects
outreg2 using "$outfile", keep(treat) nocon 2aster dec(3) word ap ///
addstat(pre, $prem, effect, $effectm, transbeta, $transbeta) 

use "$infile", clear
keep if rent <= 938 & rent != .
reghdfe logwater treat, absorb(datasethome datasetweek) cluster(home)
leveleffects
outreg2 using "$outfile", keep(treat) nocon 2aster dec(3) word ap ///
addstat(pre, $prem, effect, $effectm, transbeta, $transbeta) 

use "$infile", clear
keep if rent > 938 & rent != .
reghdfe logwater treat, absorb(datasethome datasetweek) cluster(home)
leveleffects
outreg2 using "$outfile", keep(treat) nocon 2aster dec(3) word ap ///
addstat(pre, $prem, effect, $effectm, transbeta, $transbeta) 


* F-tests

* Rooms
use "$infile", clear
drop if rooms == .
gen dgroup = (rooms > 2)
gen treat1 = 0
replace treat1 = treat if dgroup == 0
gen treat2 = 0
replace treat2 = treat if dgroup == 1
foreach var in datasethome datasetweek home {
	gen `var'1 = 0
	replace `var'1 = `var' if dgroup == 0
	gen `var'2 = 0
	replace `var'2 = `var' if dgroup == 1
	egen s`var' = group(`var'1 `var'2)
}
reghdfe logwater treat1 treat2 dgroup, absorb(sdatasethome sdatasetweek) cluster(home)
test _b[treat1] = _b[treat2]

* m2
use "$infile", clear
drop if m2 == .
gen dgroup = (m2 > 65)
gen treat1 = 0
replace treat1 = treat if dgroup == 0
gen treat2 = 0
replace treat2 = treat if dgroup == 1
foreach var in datasethome datasetweek home {
	gen `var'1 = 0
	replace `var'1 = `var' if dgroup == 0
	gen `var'2 = 0
	replace `var'2 = `var' if dgroup == 1
	egen s`var' = group(`var'1 `var'2)
}
reghdfe logwater treat1 treat2 dgroup, absorb(sdatasethome sdatasetweek) cluster(home)
test _b[treat1] = _b[treat2]

* Rent
use "$infile", clear
drop if rent == .
gen dgroup = (rent > 938)
gen treat1 = 0
replace treat1 = treat if dgroup == 0
gen treat2 = 0
replace treat2 = treat if dgroup == 1
foreach var in datasethome datasetweek home {
	gen `var'1 = 0
	replace `var'1 = `var' if dgroup == 0
	gen `var'2 = 0
	replace `var'2 = `var' if dgroup == 1
	egen s`var' = group(`var'1 `var'2)
}
reghdfe logwater treat1 treat2 dgroup, absorb(sdatasethome sdatasetweek) cluster(home)
test _b[treat1] = _b[treat2]
